#ifndef QMACHINE_H
#define QMACHINE_H

#include "machine_global.h"

#include <QObject>
#include <QMap>

class QMachineValue;

struct tagValueGroup
{
    QList<QMachineValue*>           m_values;
    QString                         m_name;
    QMap<QString,QMachineValue*>    m_code_to_value;
    QMap<int,QMachineValue*>        m_address_to_value;
};

class MACHINELIB_EXPORT QMachine : public QObject
{
    Q_OBJECT
public:
    explicit QMachine(QObject *parent = 0);
    ~QMachine();
    
    void    add_group(const QString &name);
    bool    add_value(const QString &group,QMachineValue* value);

    tagValueGroup * get_group(const QString &name);
    tagValueGroup * get_group(int index);

    int             get_group_count();

    QList<tagValueGroup*>   get_groups();

    QMachineValue*  get_value(const QString &code);
    QMachineValue*  get_value(int address);

    QMachineValue*  get_runtime_value(int index);
    int             get_runtime_count();
    void            add_runtime_value(QMachineValue* value);
    QList<QMachineValue*> get_runtimes();
    void            clear_runtime_value();
    void            add_all_runtime_value(QMachineValue* value);
    QList<QMachineValue*> get_all_runtimes();

    void    clear();

    QList<QMachineValue*>  get_start_list();

    bool            check_value_right(QMachineValue* value);
    QString         type();
    void            set_type(const QString &type);
    QString         version();
    void            set_version(const QString &ver);

    void            set_status(int status);
    int             get_status();
signals:
    void            status_changed();
public slots:
protected:
    QList<tagValueGroup*>           m_groups;
    QList<QMachineValue*>           m_runtime_value;
    QList<QMachineValue*>           m_all_runtime_value;
    QMap<QString,tagValueGroup*>    m_name_to_group;

    QString         m_type;
    QString         m_version;
    QList<QMachineValue*>           m_start_list;
    int             m_machine_status;
};

#endif // QMACHINE_H
